package Train;

import java.util.Scanner;

public class fourDay {
    public static void main1(String[] args) {
        //回文字符串串
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String a = scanner.next();
            String b = scanner.next();
            //将b插入a中查看是否回文字符串
            //可以通过逆转字符串然后对比是否一样,也可以通过首尾互换
            int count = 0;
            for (int i = 0; i <= a.length(); i++) {
                StringBuilder str = new StringBuilder();
                str.append(a.substring(0,i));
                str.append(b);
                str.append(a.substring(i,a.length()));
                String tmp = str.toString();
                str.reverse();
                if(tmp.equals(str.toString())){
                    count++;
                }
            }
            System.out.println(count);
        }
    }

    public static void main(String[] args) {
        //连续最大和,如果<0就重新开始
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int n = scanner.nextInt();
            int[] array = new int[n];
            for (int i = 0; i < array.length; i++) {
                array[i] = scanner.nextInt();
            }
            int max = Integer.MIN_VALUE;//记录最大值
            int sum = 0;//记录当前值,如果<0就重新计算
            for (int i = 0; i < array.length; i++) {
                sum+=array[i];
                if(sum > max){
                    max = sum;
                }
                if(sum <= 0){
                    sum = 0;
                }
            }
            System.out.println(max);
        }
    }

}
